package com.platform.destiny.config;

import com.platform.destiny.common.Constant;
import com.platform.destiny.dto.UserDto;
import com.platform.destiny.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
@Configuration
public class AppLogoutHandler implements LogoutSuccessHandler {


    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
                                Authentication authentication) throws IOException, ServletException {

        String token = request.getHeader(Constant.token_name);
        UserDto userDto = JwtUtils.parseToken(token);
        SecurityContextHolder.getContext().setAuthentication(null);

    }
}
